package school

func getAnswerGroupFun(id uint, userId uint, isPass uint) (map[string]interface{}, error) {
	var answerGroup AnswerGroup
	if id != 0 {
		if err := DB1().Where("id = ?", id).First(&answerGroup).Error; err != nil {
			return nil, err
		}
	}
	if userId != 0 {
		if err := DB1().Where("user_id = ?", userId).First(&answerGroup).Error; err != nil {
			return nil, err
		}
	}

	var questions []Question
	err := DB1().Where("group_id = ?", answerGroup.ID).Find(&questions).Error
	if err != nil {
		return nil, err
	}

	questionDto := Question{}.toDtoList(questions)
	return map[string]interface{}{
		"answer_group": answerGroup,
		"questions":    questionDto,
	}, nil
}
